import math


def Frustum_of_a_cone(data: dict):
    """
    计算圆台，输入一个字典，返回一个字典
    :param data:字典
    {
    r：圆台上圆半径
    R：圆台下圆半径
    h：圆台高度
    }

    :return res:字典
    {
    "Generatrix_length"：母线长度
    "Cone_side_area"：圆台侧面积
    "Cone_surface_area"：圆台表面积
    "Cone_volume"：圆台体积
    "Center_angle"：展开后圆心角
    "Radius_upper_arc"：展开后上圆弧半径
    "Radius_lower_arc"：展开后下圆弧半径
    "Upper_arc_length"：展开后上圆弧长
    "Lower_arc_length"：展开后下圆弧长
    "Upper_chord_length"：展开后上圆弦长
    "Lower_chord_length"：展开后下圆弦长
    }
    """
    if "r" in data and "R" in data and "h" in data:
        r = data["r"]
        R = data["R"]
        h = data["h"]
        if r == R:
            print("图形为圆柱体")
            Generatrix_length = r
            Cone_side_area = math.pi * Generatrix_length * (r + R)
            Cone_surface_area = Cone_side_area + (R * R + r * r) * math.pi
            Cone_volume = (R * R + R * r + r * r) * math.pi * h / 3
            Center_angle = 0
            Upper_arc_length = 2 * math.pi * r
            Lower_arc_length = 2 * math.pi * R
            return{
                "Generatrix_length" : Generatrix_length,
                "Cone_side_area" : Cone_side_area,
                "Cone_surface_area" : Cone_surface_area,
                "Cone_volume" : Cone_volume,
                "Center_angle" : Center_angle,
                "Upper_arc_length" : Upper_arc_length,
                "Lower_arc_length" : Lower_arc_length
            }
        else:
            Generatrix_length = math.sqrt((R - r) * (R - r) + h * h)
            Cone_side_area = math.pi * Generatrix_length * (r + R)
            Cone_surface_area = Cone_side_area + (R * R + r * r) * math.pi
            Cone_volume = (R * R + R * r + r * r) * math.pi * h / 3
            Center_angle = ((R - r) / Generatrix_length) * 360
            Radius_upper_arc = r * Generatrix_length
            Radius_lower_arc = R * Generatrix_length
            Upper_arc_length = 2 * math.pi * r
            Lower_arc_length = 2 * math.pi * R
            Upper_chord_length = 2 * r * math.sin(math.radians(Center_angle) / 2)
            Lower_chord_length = 2 * R * math.sin(math.radians(Center_angle) / 2)
    else:
        pass
    return {
        'Generatrix_length': Generatrix_length,
        "Cone_side_area": Cone_side_area,
        "Cone_surface_area": Cone_surface_area,
        "Cone_volume": Cone_volume,
        "Center_angle": Center_angle,
        "Radius_upper_arc": Radius_upper_arc,
        "Radius_lower_arc": Radius_lower_arc,
        "Upper_arc_length": Upper_arc_length,
        "Lower_arc_length": Lower_arc_length,
        "Upper_chord_length": Upper_chord_length,
        "Lower_chord_length": Lower_chord_length
    }


def test():
    """
    测试函数
    :return:
    """
    data = {
        "r": 2,
        "R": 2,
        "h": 2
    }
    res = Frustum_of_a_cone(data)
    print(res)


test()
